<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>主页</title>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="${pageContext.request.contextPath}/js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <div style="margin: 5px">
        <a class="btn btn-primary" href="${pageContext.request.contextPath}/UserBlog/findBlogByPage">返回</a>
    </div>
    <p style="text-align: center;" class="bg-info">---</p>
    <br>

    <!-- 显示的信息框 -->
    <c:if test="${requestScope.update_msg!=null}">
        <div class="alert alert-warning alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert">
                <span>&times;</span></button>
            <strong>${requestScope.update_msg}</strong>
        </div>
    </c:if>
    <div>
        <%--用户上传展示头像用--%>
        <img align="right" src="${pageContext.request.contextPath}/headImg/${sessionScope.user.path}"
             class="img-thumbnail" width="150" height="150">
        <form method="post" action="${pageContext.request.contextPath}/User/addImg" enctype="multipart/form-data">
            <div class="form-group">
                <label for="exampleInputFile">头像上传</label>
                <input type="file" id="exampleInputFile" name="imgFile">
                <button type="submit" class="btn btn-default">上传</button>
            </div>
        </form>
    </div>
    <p style="text-align: center;" class="bg-info">---</p>


    <form class="form-inline"
          action="${pageContext.request.contextPath}/Label/addLabel?priorLabel=${requestScope.labelPrior}"
          method="post">
        <%--展示用户的文章--%>
        <c:forEach items="${requestScope.userBlogPageBean.list}" var="blog" varStatus="s">
            <h4><input type="checkbox" name="bid" value="${blog.id}">
                <a href="${pageContext.request.contextPath}/UserBlog/userBlog?id=${blog.id}&uid=${blog.uid}">
                        ${blog.title}</a></h4>
            <blockquote>
                <c:if test="${blog.content.length()>=20}">
                    <p>${blog.content.substring(0,20)}...</p>
                </c:if>
                <c:if test="${blog.content.length()<20}">
                    <p>${blog.content}</p>
                </c:if>
            </blockquote>
        </c:forEach>
        <div align="right">
            <table class="table table-hover">
                <tr>
                    <th id="backLast" colspan="2">返回上级收藏</th>
                </tr>
                <tr>
                    <th>#</th>
                    <th>标签名</th>
                </tr>
                <c:if test="${requestScope.labelPage!=null}">
                    <c:forEach items="${requestScope.labelPage}" var="label" varStatus="s">
                        <tr>
                            <td><input type="radio" name="labelId" value="${label.id}"></td>
                            <td>
                                <a href="${pageContext.request.contextPath}/UserBlog/findUserBlog?labelPrior=${label.id}">${label.content}</a>
                            </td>
                        </tr>
                    </c:forEach>
                </c:if>
                <c:if test="${requestScope.labelPage==null}">
                    <tr>
                        <td colspan="2">没有子标签了哦</td>
                    </tr>
                </c:if>
                <tr>
                    <td>
                        <div class="form-group">
                            <input type="text" name="newLabel" class="form-control" id="exampleInputEmail3"
                                   placeholder="添加分组名称">
                        </div>
                    </td>
                    <td><input class="btn btn btn-primary" type="submit" value="添加到分组"></td>
                </tr>
            </table>
        </div>
    </form>


    <%--下面这里是分页的数据--%>
    <div>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <%--这个li就是代表上一页的了--%>
                <c:if test="${requestScope.userBlogPageBean.currentPage==1}">
                <li class="disabled">
                        <%--这里是一个禁用,但页码为1的时候不让用--%>
                    </c:if>
                    <c:if test="${requestScope.userBlogPageBean.currentPage!=1}">
                <li>
                    </c:if>
                    <a href="${pageContext.request.contextPath}/UserBlog/findUserBlog?currentPage=${requestScope.userBlogPageBean.currentPage-1}&rows=5&labelPrior=${requestScope.labelPrior}"
                       aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>


                <c:forEach begin="1" end="${requestScope.userBlogPageBean.totalPage}" var="i">
                    <%--上面这个显示的是激活状态
                    下面显示的是未激活状态 --%>
                    <c:if test="${requestScope.userBlogPageBean.currentPage==i}">
                        <li class="active"><a
                                href="${pageContext.request.contextPath}/UserBlog/findUserBlog?currentPage=${i}&rows=5&labelPrior=${requestScope.labelPrior}">${i}</a>
                        </li>
                    </c:if>
                    <c:if test="${requestScope.userBlogPageBean.currentPage!=i}">
                        <li>
                            <a href="${pageContext.request.contextPath}/UserBlog/findUserBlog?currentPage=${i}&rows=5&labelPrior=${requestScope.labelPrior}">${i}</a>
                        </li>
                    </c:if>
                </c:forEach>

                <c:if test="${requestScope.userBlogPageBean.currentPage==requestScope.userBlogPageBean.totalPage}">
                <li class="disabled">
                    </c:if>
                    <c:if test="${requestScope.userBlogPageBean.currentPage!=requestScope.userBlogPageBean.totalPage}">
                <li>
                    </c:if>
                    <a href="${pageContext.request.contextPath}/UserBlog/findUserBlog?currentPage=${requestScope.userBlogPageBean.currentPage+1}&rows=5&labelPrior=${requestScope.labelPrior}"
                       aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>

                <span style="font-size: 25px;margin: 5px">
                共${requestScope.userBlogPageBean.totalCount}条记录,共${requestScope.userBlogPageBean.totalPage}页
                </span>
            </ul>
        </nav>
    </div>
</div>


<script>
    document.getElementById("backLast").onclick = function () {
        if (${requestScope.labelPrior!=null}) {
            window.history.back(-1);
        }
    }

</script>
</body>
</html>
